/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SISAC.DACEA.DA;

import SISAC.DACEA.DS.Conexion;
import SISAC.DACEA.ENTITY.Alumno;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;

/**
 *
 * @author Abel
 */
public class AlumnoDA {
    public synchronized Alumno registrarAlumno(Alumno oAlumno){
        Connection cn=null;
        CallableStatement call=null;
        
        try {
            String sql= "{CALL registrarAlumno(?,?,?,?,?,?,?)}";
           
            cn=new Conexion().getConnection();
            call=cn.prepareCall(sql);
            
            call.registerOutParameter(1, Types.INTEGER);
            call.setString(2, oAlumno.getDni());
            call.setString(3, oAlumno.getNombreAlumno());
            call.setString(4, oAlumno.getApePaterno());
            call.setString(5, oAlumno.getApeMaterno());
            call.setString(6, oAlumno.getEmail());
            call.setString(7, oAlumno.getTelefono()); 
            
            call.executeUpdate();
            
            //recuperando el codigoAlumno
            Alumno oAlumno1 = new Alumno();
            oAlumno1.setCodigoAlumno(call.getInt(1));
           return oAlumno1; 
        } catch (Exception e) {
            System.out.println("Error al registrar Alumno"+e);
            return null;
        }
    }
    
}
